﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepMomWeaningCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepMomWeaningHandler
{
    public class SheepWeaningCreateHandler:IRequestHandler<SheepWeaningCreateCommand,Results<int>>
    {
        private readonly ISheepWeaningService _sheepWeanService;
        private readonly IMapper _mapper;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sheepWeanService"></param>
        /// <param name="mapper"></param>
        public SheepWeaningCreateHandler(ISheepWeaningService sheepWeanService, IMapper mapper)
        {
            _sheepWeanService = sheepWeanService;
            _mapper = mapper;
        }

        /// <summary>
        /// 种母断奶添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(SheepWeaningCreateCommand request, CancellationToken cancellationToken)
        {
            var result = _mapper.Map<List<SheepMomWeaning>>(request.WeanList);

            return Results<int>.DataResult(await _sheepWeanService.SheepWeaningAdd(result));
        }
    }
}
